package org.swim.core.entities;

// Generated Dec 7, 2012 12:57:21 AM by Hibernate Tools 3.4.0.CR1

import static javax.persistence.GenerationType.IDENTITY;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import org.swim.remote.entities.IAbility;
import org.swim.remote.entities.IUser;

/**
 * Ability generated by hbm2java
 */
@Entity
@Table(name = "Ability", catalog = "jboss", uniqueConstraints = @UniqueConstraint(columnNames = "name"))
public class Ability extends SwimEntity implements java.io.Serializable,
		IAbility {

	private static final long serialVersionUID = 1L;

	private Integer id;
	private String name;
	private Status status = Status.REQUESTED;
	private String tag;
	private List<User> users = new ArrayList<User>();

	public Ability() {
	}

	public Ability(String name, Status status) {
		this.name = name;
		this.status = status;
	}

	public Ability(String name, Status status, String category, List<User> users) {
		this.name = name;
		this.status = status;
		this.tag = category;
		this.users = users;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.swim.entities.IAbility#getId()
	 */
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.swim.entities.IAbility#getName()
	 */
	@Column(name = "name", unique = true, nullable = false, length = 45)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.swim.entities.IAbility#getStatus()
	 */
	@Enumerated(EnumType.STRING)
	@Column(name = "status", nullable = false, length = 10, columnDefinition = "ENUM('REQUESTED', 'CONFIRMED', 'REJECTED'")
	public Status getStatus() {
		return this.status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.swim.entities.IAbility#getTag()
	 */
	@Column(name = "tag", length = 45)
	public String getTag() {
		return this.tag;
	}

	public void setTag(String tag) {
		this.tag = tag;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.swim.entities.IAbility#getUsers()
	 */
	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name = "AbilityUser", catalog = "jboss", joinColumns = { @JoinColumn(name = "abilityId", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "userId", nullable = false, updatable = false) })
	public List<User> getUsers() {
		return this.users;
	}
	

	public void setUsers(List<User> users) {
		this.users = users;
	}

	/* --------------------All method for interfaces------------------------*/
	@Transient
	public Set<IUser> getUsersSet() {
		Set<IUser> list = new HashSet<IUser>(getUsers());
		return list;
	}

}
